home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UTIL / MEMORY / OLD / MEM208SRC / FSLib / c / ModuleWrap < prev    next >
Text File  |  1993-08-22  |  5KB  |  180 lines

  1. /* Original code (c) Acorn Computers Ltd, 1992-3 */
  2.  
  3. /* $Id: c.ModuleWrap 3.1 93/03/09 20:08:52 brian Exp $ */
  4. /*
  5.      Module wrapping for FS
  6.  
  7. */
  8.  
  9. #include "FS.h"
  10.  
  11. /* Define for FS with interactive freespace support */
  12. #define XFree_Register          0x644c0
  13. #define XFree_DeRegister        0x644c1
  14.  
  15. /* Define TRACESERVICE in order to output trace of service calls */
  16. /* #define TRACESERVICE */
  17.  
  18.  
  19. /*
  20.         This is the finalisation code
  21. */
  22. static void fs_finalise
  23. ( void )
  24. {
  25.         _kernel_swi_regs r;
  26.  
  27.         /*
  28.                 Close your filing system down here and free up all your memory NOW.
  29.                 If you do not then all your filing system's junk is going to be left
  30.                 cluttering up the RMA as this module is just about to be killed.
  31.         */
  32.         fs_terminate();
  33.         Terminate_FileEntrys();
  34. #ifdef XFree_Register
  35.         r.r[0] = FilingSystemInformationWord & 0xFF; /* Filing system numbe */
  36.         _kernel_swi( XFree_DeRegister, &r, &r );
  37. #endif
  38.         r.r[0] = FSControl_RemoveFilingSystem;
  39.         r.r[1] = (int)FilingSystemName;
  40.  
  41.         _kernel_swi( XOS_Bit | OS_FSControl, &r, &r );
  42. }
  43.  
  44. /*
  45.         Declare FS to FileSwitch
  46. */
  47. static _kernel_oserror *declare_fs
  48. ( void *private_word )
  49. {
  50.         _kernel_oserror *err;
  51.         _kernel_swi_regs r;
  52.         int information_block[ Information_Block_Size ];
  53.  
  54.         information_block[0] = (int)FilingSystemName                    - (int)Image_RO_Base;
  55.         information_block[1] = (int)ModuleName                          - (int)Image_RO_Base;
  56.         information_block[2] = (int)&veneer_fsentry_open                - (int)Image_RO_Base;
  57.         information_block[3] = (int)&veneer_fsentry_getbytes            - (int)Image_RO_Base;
  58.         information_block[4] = (int)&veneer_fsentry_putbytes            - (int)Image_RO_Base;
  59.         information_block[5] = (int)&veneer_fsentry_args                - (int)Image_RO_Base;
  60.         information_block[6] = (int)&veneer_fsentry_close               - (int)Image_RO_Base;
  61.         information_block[7] = (int)&veneer_fsentry_file                - (int)Image_RO_Base;
  62.         information_block[8] = FilingSystemInformationWord;
  63.         information_block[9] = (int)&veneer_fsentry_func                - (int)Image_RO_Base;
  64.         information_block[10] = (int)&veneer_fsentry_gbpb               - (int)Image_RO_Base;
  65.  
  66.         r.r[0] = FSControl_AddFilingSystem;
  67.         r.r[1] = (int)Image_RO_Base;
  68.         r.r[2] = (int)information_block - (int)Image_RO_Base;
  69.         r.r[3] = (int)private_word;
  70.  
  71.         err = _kernel_swi( XOS_Bit | OS_FSControl, &r, &r );
  72. #ifdef XFree_Register
  73.         if ( !err )
  74.         { r.r[0] = FilingSystemInformationWord & 0xFF; /* Filing system numbe */
  75.           r.r[1] = (int)&veneer_fsentry_free;
  76.           r.r[2] = (int)private_word;
  77.           _kernel_swi( XFree_Register, &r, &r );
  78.         }
  79. #endif
  80.         return err;
  81. }
  82.  
  83. /*
  84.         This is the initialisation code
  85. */
  86. _kernel_oserror *fs_initialise
  87. ( char *cmd_tail, int podule_base, void *private_word )
  88. {
  89.         _kernel_oserror *err;
  90.         /*
  91.                 These keep the compiler quiet.
  92.         */
  93.         cmd_tail = cmd_tail;
  94.         podule_base = podule_base;
  95.  
  96.         /*
  97.                 Place your filing system's initialisation here. If an error occurs then
  98.                 you can skip the 'declaring yourself to FileSwitch' bit.
  99.         */
  100.         err = Initialise_FileEntrys( private_word );
  101.  
  102.         if ( !err )
  103.           err = declare_fs( private_word );
  104.  
  105.         if ( !err )
  106.           atexit( fs_finalise );
  107.  
  108.         return err;
  109. }
  110.  
  111. /*
  112.         Service call handler
  113. */
  114.  
  115. #ifdef TRACESERVICE
  116. static struct {int svc; char *name;} svcs[] =
  117. {
  118.  {0x00,"Serviced"},
  119.  {0x04,"UKCommand"},
  120.  {0x06,"Error"},
  121.  {0x07,"UKByte"},
  122.  {0x08,"UKWord"},
  123.  {0x09,"Help"},
  124.  {0x0b,"ReleaseFIQ"},
  125.  {0x0c,"ClaimFIQ"},
  126.  {0x11,"Memory"},
  127.  {0x12,"StartUpFS"},
  128.  {0x27,"Reset"},
  129.  {0x28,"UKConfig"},
  130.  {0x29,"UKStatus"},
  131.  {0x2a,"NewApplication"},
  132.  {0x40,"FSRedclare"},
  133.  {0x41,"Print"},
  134.  {0x42,"LookupFileType"},
  135.  {0x43,"International"},
  136.  {0x44,"Keyhandler"},
  137.  {0x45,"PreReset"},
  138.  {0x46,"ModeChange"},
  139.  {0x47,"ClaimFIQinBackground"},
  140.  {0x48,"ReAllocatePorts"},
  141.  {0x49,"StartWimp"},
  142.  {0x4a,"StartedWimp"},
  143.  {0x4b,"StartFiler"},
  144.  {0x4c,"StartedFiler"},
  145.  {0x4d,"PreModeChange"},
  146.  {0x4e,"MemoryMoved"},
  147.  {0x4f,"FilerDying"},
  148.  {0x50,"ModeExtension"},
  149.  {0x51,"ModeTranslation"},
  150.  {0x52,"MouseTrap"},
  151.  {0x53,"WimpCloseDown"},
  152.  {0x54,"Sound"},
  153.  {0x55,"NetFS"},
  154.  {0x56,"EconetDying"},
  155.  {0x57,"WimpReportError"},
  156.  {-1,"Something else"}
  157. };
  158. #endif
  159.  
  160. void fs_service
  161. ( int service_number, _kernel_swi_regs *r, void *private_word )
  162. {
  163. #ifdef TRACESERVICE
  164. { int i;
  165.  for (i=0;svcs[i].svc>=0;i++) if (svcs[i].svc==service_number)break;
  166.  printf("Service_%s (%#x)%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\r\n",svcs[i].name,service_number,*r);
  167. }
  168. #endif
  169.         r=r;
  170.         switch( service_number )
  171.         {
  172.         case Service_FSRedeclare:
  173.                 declare_fs( private_word );
  174.                 break;
  175.         /*
  176.                 Handle other service calls here
  177.         */
  178.         }
  179. }
  180.